#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

typedef struct timeval timex;

static timex start, end;

timex checktime()
{
  struct timeval now;
  gettimeofday(&now,NULL);
  return now;
}

void starttime() {
  start = checktime();
}

void endtime() {
  end = checktime();
}


long timelapse() {
  long mtime, seconds, useconds;

  endtime();

  seconds  = end.tv_sec  - start.tv_sec;
  useconds = end.tv_usec - start.tv_usec;

  mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;

  return mtime;
}
